import { action, observable } from 'mobx';
import { message } from 'antd';
import { WeaTools, WeaLocaleProvider } from 'ecCom';
import * as API_Follow from '../apis/followTypeSetting';
const { ls } = WeaTools;
const getLabel = WeaLocaleProvider.getLabel;


export default class FollowTypeSettingStore {
    @observable colorSetting = false;//colorpicker
    @observable colorValue = '#6aa84f';
    @observable operateId = '';//颜色改变参照id
    @observable showDialog = false;
    @observable flowTypeData = '';//弹框数据
    @observable tagList = observable.map ? observable.map({}) : asMap({});//组件数据
    @observable reqid='';//requestionid
    @observable formTagList=null;
    @observable disabledArray=[];
    @observable callBackFunc = ()=>{};
    @observable saveDialogObj=null;
    openType="";
    @action
    setFunc = (variable, param) => {
        this[variable] = param
        // switch (variable) {
        //     case 'colorSetting':
        //         this.colorSetting = param
        //         break
        //     case 'colorValue':
        //         this.colorValue = param
        //         break
        //     case 'operateId':
        //         this.operateId = param
        //         break
        //     case 'showDialog':
        //         this.showDialog = param
        //         break
        // }
    }

    @action
    setState =  (obj,callback) => {
        const keys = Object.keys(obj);
        for(let key of keys){
            this[key] = obj[key];
        }

        typeof callback === 'function' && callback()
    }
    //获取关注列表
    @action
    getAttentionTypeSet = (item) =>{
        API_Follow.getAttentionTypeSet(item).then((data)=>{
            // console.log(data)
            if(item==="com"){//组件数据
                // this.tagList =data
                this.tagList.set("datas", data.datas);
            }else if(typeof(item)=='object'){
                this.saveDialogObj = item
                this.flowTypeData = data
                this.saveDialogObj.loadData()
            }else if(item=="refresh"){// if(item=="refresh")
                this.flowTypeData = data
                this.saveDialogObj.loadData()
            }
            
        });
    }
    //单个流程关注标签
    @action
    getWorkflowAttentionTypeSet=(param)=>{
        this.reqid = param
        API_Follow.getWorkflowAttentionTypeSet(param).then((data)=>{
            this.tagList.set("datas", data.datas);
            this.tagList.set("title", data.title);
		});
    }
    @action//表单标签
    getWorkflowFormAttentionTypeSet=(param)=>{
        this.reqid = param
        API_Follow.getWorkflowAttentionTypeSet(param).then((data)=>{
            this.formTagList = data
		});
    }
    //组件保存标签
    @action
    saveAttentionTypeSet = (params,fun) =>{
        let _this=this
        API_Follow.saveAttentionTypeSet(params).then((data)=>{
            if(params.src=="saveData2"){
                // _this.getAttentionTypeSet('com')
                _this.getWorkflowAttentionTypeSet(_this.reqid)
                _this.getAttentionTypeSet(window.flowTypeSelf)
            }else if(params.src=="saveData"){
                _this.getAttentionTypeSet(window.flowTypeSelf)
                _this.getWorkflowAttentionTypeSet(_this.reqid)
                typeof fun =='function'&&fun()
            }
		});
    }
    @action
    batchdelAll = (params) =>{
        API_Follow.batchdelAll(params).then((data)=>{
            // console.log(data)
        })
    }
    //标签保存
    @action
    saveAttention = (params,mode,callBackFunc) =>{
            API_Follow.saveAttention(params).then((data)=>{
                if(data.success==="1"){
                    if(mode==="single"){
                        let divId = "attentionDiv_"+params.requestids+"_"+params.ids+"_"+params.rand;
                        jQuery("#"+divId).remove();
                        this.getWorkflowAttentionTypeSet(this.reqid);      
                    }else if(mode==="formrefresh"){
                      typeof callBackFunc=='function'&& callBackFunc();
                    }else {
                      typeof callBackFunc=='function'&& callBackFunc();
                    }
                }
            }); 
    }
   
}